/*
 * @Description:
 * @Version: 1.0
 * @Author: liguansheng
 * @Date: 2022-08-25 14:01:03
 * @LastEditors: liguansheng
 * @LastEditTime: 2022-08-25 16:03:03
 */
import axios from '@/utils/request'

import { IApiScope, ICreateApiScope, IUpdateApiScope } from './types/apiScope'
import { IPageResult } from './types/base'

// 获取所有apiScope
export function getAllApiScopes() {
  return axios<IApiScope[]>({
    url: '/api/identity-server/api-scopes/all',
    method: 'get',
  })
}

// 新增api资源详情
export function createApiScope(data: ICreateApiScope) {
  return axios<IApiScope>({
    url: '/api/identity-server/api-scopes',
    method: 'post',
    data,
  })
}

// 删除api资源
export function deleteApiScope(id: string) {
  return axios({
    url: '/api/identity-server/api-scopes',
    method: 'delete',
    params: {
      id,
    },
  })
}

// 获取api资源详情
export function updateApiScope(id: string, data: IUpdateApiScope) {
  return axios<IApiScope>({
    url: `/api/identity-server/api-scopes/${id}`,
    method: 'put',
    data,
  })
}

// 分页获取api资源
export function pagedApiScopes(currentPage = 1, take = 10, filter = '') {
  return axios<IPageResult<IApiScope>>({
    url: '/api/identity-server/api-scopes',
    method: 'get',
    params: {
      skipCount: take * (currentPage - 1),
      maxResultCount: take,
      filter,
    },
  })
}

// 获取api资源详情
export function getApiScope(id: string) {
  return axios<IApiScope>({
    url: `/api/identity-server/api-scopes/${id}`,
    method: 'get',
  })
}
